#pragma once

#include <drogon/HttpController.h>
#include <drogon/utils/Utilities.h>
#include <../models/Users.h>
#include <../plugins/PasswordUtils.h>
#include <jwt-cpp/jwt.h>

using namespace drogon;

class loginController : public drogon::HttpController<loginController>
{
  public:
    METHOD_LIST_BEGIN
        ADD_METHOD_TO(loginController::login, "/api/login", Post);
        ADD_METHOD_TO(loginController::logout, "/api/logout", Post);
        ADD_METHOD_TO(loginController::checkAuth, "/api/auth/check", Get);
        ADD_METHOD_TO(loginController::registerPage, "/register", Get);
        ADD_METHOD_TO(loginController::dashboard, "/dashboard", Get);
    METHOD_LIST_END

    void login(const HttpRequestPtr& req,
               std::function<void(const HttpResponsePtr&)>&& callback);
    
    void logout(const HttpRequestPtr& req,
                std::function<void(const HttpResponsePtr&)>&& callback);
    
    void checkAuth(const HttpRequestPtr& req,
                   std::function<void(const HttpResponsePtr&)>&& callback);

    void registerPage(const HttpRequestPtr& req,
                      std::function<void(const HttpResponsePtr&)>&& callback);
    
    void dashboard(const HttpRequestPtr& req,
                   std::function<void(const HttpResponsePtr&)>&& callback);
  
private:
    Json::Value createUserResponse(const drogon_model::jol::Users& user);
};
